<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>每日一面--Files工具类 | Celts</title><meta name="author" content="PaulGeorge"><meta name="copyright" content="PaulGeorge"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="每天一篇面试小知识  本篇着重介绍一下   写在前面 在我们平常工作中经常会遇到有关于文件的相关处理操作，相关的API也有不同，如果条件受限，那么我们可以使用jdk自带的Files类; 如果又引入apache依赖，就可以使用FileUtiles工具类。">
<meta property="og:type" content="article">
<meta property="og:title" content="每日一面--Files工具类">
<meta property="og:url" content="https://curry3035.gitee.io/posts/55119/index.html">
<meta property="og:site_name" content="Celts">
<meta property="og:description" content="每天一篇面试小知识  本篇着重介绍一下   写在前面 在我们平常工作中经常会遇到有关于文件的相关处理操作，相关的API也有不同，如果条件受限，那么我们可以使用jdk自带的Files类; 如果又引入apache依赖，就可以使用FileUtiles工具类。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://curry3035.gitee.io/img/avatar.jpg">
<meta property="article:published_time" content="2023-01-01T01:00:00.000Z">
<meta property="article:modified_time" content="2023-04-07T13:03:57.782Z">
<meta property="article:author" content="PaulGeorge">
<meta property="article:tag" content="进阶">
<meta property="article:tag" content="Files">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://curry3035.gitee.io/img/avatar.jpg"><link rel="shortcut icon" href="/img/ic.ico"><link rel="canonical" href="https://curry3035.gitee.io/posts/55119/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":false,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: PaulGeorge","link":"链接: ","source":"来源: Celts","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '每日一面--Files工具类',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-04-07 21:03:57'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/background.css"><link rel="stylesheet" href="/css/my.css"><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="Celts"><span class="site-name">Celts</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">每日一面--Files工具类</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-01-01T01:00:00.000Z" title="发表于 2023-01-01 09:00:00">2023-01-01</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-07T13:03:57.782Z" title="更新于 2023-04-07 21:03:57">2023-04-07</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%AE%9E%E8%B7%B5%E7%AF%87/">实践篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.6k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>7分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="每日一面--Files工具类"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>每天一篇面试小知识</p>
</blockquote>
<p><strong>本篇着重介绍一下</strong></p>
<hr>
<p><img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2023-01-01_20-19-42.png"></p>
<p><strong>写在前面</strong></p>
<p>在我们平常工作中经常会遇到有关于文件的相关处理操作，相关的<code>API</code>也有不同，如果条件受限，那么我们可以使用<code>jdk</code>自带的<code>Files</code>类; 如果又引入<code>apache</code>依赖，就可以使用<code>FileUtiles</code>工具类。</p>
<span id="more"></span>



<h3 id="File类"><a href="#File类" class="headerlink" title="File类"></a>File类</h3><h4 id="作用"><a href="#作用" class="headerlink" title="作用"></a>作用</h4><ul>
<li>获取路径（绝对路径和相对路径）</li>
<li>判断文件是否存在</li>
<li>创建、删除文件</li>
</ul>
<h4 id="获取路径"><a href="#获取路径" class="headerlink" title="获取路径"></a>获取路径</h4><ul>
<li><code>getAbsolutePath()</code> ：返回此File的绝对路径。</li>
<li><code>getPath() </code>：结果和getAbsolutePath一致。</li>
<li><code>getName() </code>：返回文件名或目录名。</li>
<li><code>length() </code>：返回文件长度，以字节为单位。</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">File</span> <span class="variable">file</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(<span class="string">&quot;/usr/local/create/test.java&quot;</span>);     </span><br><span class="line">log.info(<span class="string">&quot;文件绝对路径:&#123;&#125;&quot;</span>,file.getAbsolutePath());</span><br><span class="line">log.info(<span class="string">&quot;文件构造路径:&#123;&#125;&quot;</span>,file.getPath());</span><br><span class="line">log.info(<span class="string">&quot;文件名称:&#123;&#125;&quot;</span>,file.getName());</span><br><span class="line">log.info(<span class="string">&quot;文件长度:&#123;&#125;&quot;</span>,file.length());</span><br></pre></td></tr></table></figure>

<blockquote>
<p><code>File</code>对象表示文件的时候，<code>length()</code>才会有具体值，表文件夹则无值</p>
</blockquote>
<h4 id="判断文件是否存在"><a href="#判断文件是否存在" class="headerlink" title="判断文件是否存在"></a>判断文件是否存在</h4><ul>
<li><code>exists()</code> ：判断文件或目录是否存在。</li>
<li><code>isDirectory()</code> ：判断是否为目录。</li>
<li><code>isFile()</code> ：判断是否为文件。</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">File</span> <span class="variable">file</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(<span class="string">&quot;/usr/local/create/test.java&quot;</span>);</span><br><span class="line"><span class="comment">// 判断是否存在</span></span><br><span class="line">log.info(<span class="string">&quot;/usr/local/create/test.java 是否存在:&#123;&#125;&quot;</span>,file.exists());</span><br><span class="line"><span class="comment">// 判断是文件还是目录</span></span><br><span class="line">log.info(<span class="string">&quot;/usr/local/create/test.java 是否是文件:&#123;&#125;&quot;</span>,file.isFile());</span><br></pre></td></tr></table></figure>



<h4 id="创建、删除文件"><a href="#创建、删除文件" class="headerlink" title="创建、删除文件"></a>创建、删除文件</h4><ul>
<li><code>createNewFile() </code>：文件不存在，创建一个新的空文件并返回true，文件存在，不创建文件并返回false。</li>
<li><code>delete() </code>：删除文件或目录。</li>
<li><code>mkdir() </code>：创建目录。</li>
<li><code>mkdirs()</code> ：创建目录，包括任何必需但不存在的父目录。</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 文件路径名 </span></span><br><span class="line"><span class="type">String</span> <span class="variable">path</span> <span class="operator">=</span> <span class="string">&quot;/usr/local/createfiles/test.txt&quot;</span>;</span><br><span class="line"><span class="type">File</span> <span class="variable">file1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(path);  --等价于/usr/local/createfiles/test.txt</span><br><span class="line"></span><br><span class="line"><span class="comment">// 通过父路径和子路径字符串</span></span><br><span class="line"><span class="type">String</span> <span class="variable">parent</span> <span class="operator">=</span> <span class="string">&quot;/usr/local/createfiles/parentPath&quot;</span>;</span><br><span class="line"><span class="type">String</span> <span class="variable">child</span> <span class="operator">=</span> <span class="string">&quot;childFile.txt&quot;</span>;</span><br><span class="line"><span class="type">File</span> <span class="variable">file2</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(parent, child);  --等价于于/usr/local/createfiles/parentPath/childFile.txt</span><br><span class="line"></span><br><span class="line"><span class="comment">// 通过父级File对象和子路径字符串</span></span><br><span class="line"><span class="type">File</span> <span class="variable">parentDir</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(<span class="string">&quot;/usr/local/createfiles/parentPath&quot;</span>);</span><br><span class="line"><span class="type">String</span> <span class="variable">child</span> <span class="operator">=</span> <span class="string">&quot;childFile.txt&quot;</span>;</span><br><span class="line"><span class="type">File</span> <span class="variable">file3</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(parentDir, child); --等价于于/usr/local/createfiles/parentPath/childFile.txt</span><br><span class="line">    </span><br><span class="line"><span class="comment">// createNewFile</span></span><br><span class="line"><span class="type">String</span> <span class="variable">path</span> <span class="operator">=</span> <span class="string">&quot;/usr/local/createfiles/test/&quot;</span>;</span><br><span class="line"><span class="type">String</span> <span class="variable">newFile</span> <span class="operator">=</span> <span class="string">&quot;测试文件.md&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="type">File</span> <span class="variable">temp</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(path);</span><br><span class="line"><span class="keyword">if</span> (!temp.exists()) &#123;</span><br><span class="line">    System.out.println(<span class="string">&quot;创建文件&quot;</span>);</span><br><span class="line">    temp.mkdirs();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">File</span> <span class="variable">file</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(path + newFile);</span><br><span class="line">log.info(<span class="string">&quot;file.exists()=&#123;&#125;&quot;</span>,file.exists());</span><br><span class="line">log.info(<span class="string">&quot;file.createNewFile()=&#123;&#125;&quot;</span>,file.createNewFile());</span><br><span class="line"></span><br><span class="line"><span class="type">boolean</span> <span class="variable">delete</span> <span class="operator">=</span> file.delete();</span><br><span class="line">log.info(<span class="string">&quot;delete=&#123;&#125;&quot;</span>,delete);</span><br></pre></td></tr></table></figure>

<br/>

<blockquote>
<p>一个File对象代表硬盘中实际存在的一个文件或者目录</p>
</blockquote>
<blockquote>
<p><code>delete</code>方法，如果此<code>File</code>表示目录，则目录必须为空才能删除。</p>
</blockquote>
<blockquote>
<p><code>mkdir()</code>只能创建一级目录，<code>mkdirs()</code>可以创建多级目录，开发中遇到过此问题，建议使用<code>mkdirs()</code></p>
</blockquote>
<h3 id="Paths类"><a href="#Paths类" class="headerlink" title="Paths类"></a>Paths类</h3><h4 id="作用-1"><a href="#作用-1" class="headerlink" title="作用"></a>作用</h4><p>将路径字符串或在连接时形成路径字符串的字符串序列转换为路径</p>
<blockquote>
<p> 需要传入一个绝对路径作为参数</p>
</blockquote>
<h4 id="转换为路径"><a href="#转换为路径" class="headerlink" title="转换为路径"></a>转换为路径</h4><ul>
<li><code>get()</code></li>
<li><code>startsWith(String path)</code> : 判断是否以 path 路径开始 </li>
<li><code>endsWith(String path)</code> : 判断是否以 path 路径结束 </li>
<li><code>isAbsolute() </code>: 判断是否是绝对路径</li>
<li><code>of()</code>：通过转换路径字符串或连接后形成路径字符串的字符串序列，返回一个路径</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">String</span> <span class="variable">s</span> <span class="operator">=</span> <span class="string">&quot;/usr/local/createfiles/doc/test/测试文件.md&quot;</span>;</span><br><span class="line"><span class="type">Path</span> <span class="variable">path</span> <span class="operator">=</span> Paths.get(s);</span><br><span class="line">System.out.println(path);</span><br></pre></td></tr></table></figure>





<h3 id="Files类"><a href="#Files类" class="headerlink" title="Files类"></a>Files类</h3><p>Java NIO Files类（java.nio.file.Files）操作文件（file）和文件夹（Directory）的工具类。</p>
<blockquote>
<p>Files类通常是和Paths类一起使用的</p>
</blockquote>
<h4 id="作用-2"><a href="#作用-2" class="headerlink" title="作用"></a>作用</h4><p>Java NIO2中增加了Files工具类封装提供了一些操作文件系统文件的工具方法。</p>
<h4 id="判断文件是否存在-1"><a href="#判断文件是否存在-1" class="headerlink" title="判断文件是否存在"></a>判断文件是否存在</h4><ul>
<li><code>exists()</code></li>
<li><code>notExists()</code></li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">Path</span> <span class="variable">path</span> <span class="operator">=</span> Paths.get(<span class="string">&quot;doc/test/t1/t2/t3/&quot;</span>);</span><br><span class="line">System.out.println(<span class="string">&quot;Files.exists(path) = &quot;</span> + Files.exists(path));</span><br><span class="line">System.out.println(<span class="string">&quot;Files.notExists(path) = &quot;</span> + Files.notExists(path));</span><br></pre></td></tr></table></figure>



<h4 id="删除文件"><a href="#删除文件" class="headerlink" title="删除文件"></a>删除文件</h4><ul>
<li><code>delete()</code></li>
<li><code>deleteIfExists()</code></li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">Path</span> <span class="variable">path</span> <span class="operator">=</span> Paths.get(<span class="string">&quot;doc/test/t1/t2/t3/test.md&quot;</span>);</span><br><span class="line">Files.delete(Paths.get(path));</span><br><span class="line">Files.deleteIfExists(Paths.get(path));</span><br></pre></td></tr></table></figure>

<blockquote>
<p>删除文件或者空文件夹，如果文件夹不为空的情况下会报错；建议使用<code>deleteIfExists()</code></p>
</blockquote>
<h4 id="创建文件及文件夹"><a href="#创建文件及文件夹" class="headerlink" title="创建文件及文件夹"></a>创建文件及文件夹</h4><ul>
<li><code>createDirectories()</code></li>
<li><code>createFile()</code></li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">Files.createDirectories(Paths.get(path));</span><br><span class="line">Files.createFile(Paths.get(file));</span><br></pre></td></tr></table></figure>



<h4 id="写文件"><a href="#写文件" class="headerlink" title="写文件"></a>写文件</h4><ul>
<li><code>write()</code></li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">List&lt;String&gt; list = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">list.add(<span class="string">&quot;title&quot;</span>);</span><br><span class="line">list.add(<span class="string">&quot;content&quot;</span>);</span><br><span class="line">Files.write(Paths.get(<span class="string">&quot;doc/test/file.txt&quot;</span>), list, StandardOpenOption.APPEND, StandardOpenOption.CREATE);</span><br></pre></td></tr></table></figure>



<p><strong>举个荔枝：</strong></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">try</span> (</span><br><span class="line">	<span class="type">OutputStream</span> <span class="variable">outputStream</span> <span class="operator">=</span> Files.newOutputStream(Paths.get(<span class="string">&quot;doc/test/excel.xlsx&quot;</span>));</span><br><span class="line">) &#123;</span><br><span class="line">    <span class="type">Workbook</span> <span class="variable">workbook</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">XSSFWorkbook</span>();</span><br><span class="line">    <span class="type">Sheet</span> <span class="variable">sheet</span> <span class="operator">=</span> workbook.createSheet();</span><br><span class="line">    <span class="type">Row</span> <span class="variable">row</span> <span class="operator">=</span> sheet.createRow(<span class="number">0</span>);</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) &#123;</span><br><span class="line">        <span class="type">Cell</span> <span class="variable">cell</span> <span class="operator">=</span> row.createCell(i);</span><br><span class="line">        cell.setCellValue(i);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    workbook.write(outputStream);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>





<h4 id="读文件"><a href="#读文件" class="headerlink" title="读文件"></a>读文件</h4><ul>
<li><code>readAllLines()</code></li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">List&lt;String&gt; list = Files.readAllLines(Paths.get(<span class="string">&quot;doc/test/file.txt&quot;</span>), StandardCharsets.UTF_8);</span><br><span class="line">list.forEach(System.out::println);</span><br></pre></td></tr></table></figure>

<p><strong>举个荔枝：</strong></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">try</span> (</span><br><span class="line">    <span class="type">InputStream</span> <span class="variable">inputStream</span> <span class="operator">=</span> Files.newInputStream(Paths.get(<span class="string">&quot;doc/test/excel.xlsx&quot;</span>));</span><br><span class="line">)&#123;</span><br><span class="line">    <span class="type">Workbook</span> <span class="variable">workbook1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">XSSFWorkbook</span>(inputStream);</span><br><span class="line">    <span class="type">Sheet</span> <span class="variable">sheetAt</span> <span class="operator">=</span> workbook1.getSheetAt(<span class="number">0</span>);</span><br><span class="line">    <span class="type">int</span> <span class="variable">lastRowNum</span> <span class="operator">=</span> sheetAt.getLastRowNum();</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; lastRowNum; i++) &#123;</span><br><span class="line">        <span class="type">short</span> <span class="variable">lastCellNum</span> <span class="operator">=</span> sheetAt.getRow(i).getLastCellNum();</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">j</span> <span class="operator">=</span> <span class="number">0</span>; j &lt; lastCellNum; j++) &#123;</span><br><span class="line">            System.out.print(sheetAt.getRow(i).getCell(j) + <span class="string">&quot;, &quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;<span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">    System.out.println(e.getLocalizedMessage());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="拷贝文件"><a href="#拷贝文件" class="headerlink" title="拷贝文件"></a>拷贝文件</h4><ul>
<li><code>copy()</code></li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">if</span> (Files.notExists(Paths.get(<span class="string">&quot;doc/test2/&quot;</span>)))&#123;</span><br><span class="line">    Files.createDirectories(Paths.get(<span class="string">&quot;doc/test2/&quot;</span>));</span><br><span class="line">&#125;</span><br><span class="line">Files.copy(Paths.get(<span class="string">&quot;doc/test/file.txt&quot;</span>),Paths.get(<span class="string">&quot;doc/test2/file.txt&quot;</span>));</span><br></pre></td></tr></table></figure>



<h4 id="移动文件"><a href="#移动文件" class="headerlink" title="移动文件"></a>移动文件</h4><ul>
<li><code>move()</code></li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">if</span> (Files.notExists(Paths.get(<span class="string">&quot;doc/test3/&quot;</span>)))&#123;</span><br><span class="line">    Files.createDirectories(Paths.get(<span class="string">&quot;doc/test3/&quot;</span>));</span><br><span class="line">&#125;</span><br><span class="line">Files.move(Paths.get(<span class="string">&quot;doc/test2/file.txt&quot;</span>),Paths.get(<span class="string">&quot;doc/test3/file.txt&quot;</span>));</span><br></pre></td></tr></table></figure>





<h3 id="FileUtils"><a href="#FileUtils" class="headerlink" title="FileUtils"></a>FileUtils</h3><h4 id="作用-3"><a href="#作用-3" class="headerlink" title="作用"></a>作用</h4><p><code>FileUtils</code>存在于<code>Common</code>工具库中。包含一些工具类,它们基于<code>File</code>对象工作，包括读，写，拷贝和比较文件。</p>
<h4 id="maven依赖"><a href="#maven依赖" class="headerlink" title="maven依赖"></a>maven依赖</h4><figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>commons-io<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>commons-io<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.4<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h4 id="拷贝文件-1"><a href="#拷贝文件-1" class="headerlink" title="拷贝文件"></a>拷贝文件</h4><ul>
<li><code>copyDirectory()</code>：复制文件夹（文件夹里面的文件内容也会复制）</li>
<li><code>copyDirectoryToDirectory()</code>：以子目录的形式将文件夹复制到到另一个文件夹下</li>
<li><code>copyFile()</code>：复制文件</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">FileUtils.copyDirectory(Paths.get(<span class="string">&quot;doc/test3/&quot;</span>).toFile(),Paths.get(<span class="string">&quot;doc/test2/&quot;</span>).toFile());</span><br><span class="line">FileUtils.copyDirectoryToDirectory(Paths.get(<span class="string">&quot;doc/test3/&quot;</span>).toFile(),Paths.get(<span class="string">&quot;doc/test2/&quot;</span>).toFile());</span><br><span class="line"></span><br><span class="line">FileUtils.copyFile(Paths.get(<span class="string">&quot;doc/test3/file.txt&quot;</span>).toFile(),Paths.get(<span class="string">&quot;doc/test2/file.txt&quot;</span>).toFile());</span><br></pre></td></tr></table></figure>



<h4 id="移动文件-1"><a href="#移动文件-1" class="headerlink" title="移动文件"></a>移动文件</h4><ul>
<li><code>moveDirectoryToDirectory()</code>：以子文件夹的形式移动到另外一个文件下</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">FileUtils.moveDirectoryToDirectory(Paths.get(<span class="string">&quot;doc/test3/&quot;</span>).toFile(),Paths.get(<span class="string">&quot;doc/test/&quot;</span>).toFile(),<span class="literal">false</span>);</span><br></pre></td></tr></table></figure>





<h4 id="清空、删除文件夹"><a href="#清空、删除文件夹" class="headerlink" title="清空、删除文件夹"></a>清空、删除文件夹</h4><ul>
<li><code>deleteDirectory()</code>：删除文件夹，包括文件夹和文件夹里面所有的文件</li>
<li><code>cleanDirectory()</code>：清空文件夹里面的所有的内容</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">FileUtils.deleteDirectory(Paths.get(<span class="string">&quot;doc/test2/&quot;</span>).toFile());</span><br><span class="line">FileUtils.cleanDirectory(Paths.get(<span class="string">&quot;doc/test2/&quot;</span>).toFile());</span><br></pre></td></tr></table></figure>



<h4 id="创建文件夹"><a href="#创建文件夹" class="headerlink" title="创建文件夹"></a>创建文件夹</h4><ul>
<li><code>forceMkdir()</code>：创建文件夹</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">Path</span> <span class="variable">path</span> <span class="operator">=</span> Paths.get(<span class="string">&quot;doc/test3/&quot;</span>);</span><br><span class="line">FileUtils.forceMkdir(path.toFile());</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io">PaulGeorge</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io/posts/55119/">https://curry3035.gitee.io/posts/55119/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://curry3035.gitee.io" target="_blank">Celts</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E8%BF%9B%E9%98%B6/">进阶</a><a class="post-meta__tags" href="/tags/Files/">Files</a></div><div class="post_share"><div class="social-share" data-image="/img/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/8422/" title="Excel大文件的上传"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Excel大文件的上传</div></div></a></div><div class="next-post pull-right"><a href="/posts/34600/" title="面试一下--JUC入门"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">面试一下--JUC入门</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/34600/" title="面试一下--JUC入门"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-09-10</div><div class="title">面试一下--JUC入门</div></div></a></div><div><a href="/posts/11315/" title="实践一下--Spring Security"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-06-01</div><div class="title">实践一下--Spring Security</div></div></a></div><div><a href="/posts/40042/" title="每日一面--反射"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-01</div><div class="title">每日一面--反射</div></div></a></div><div><a href="/posts/56511/" title="实践一下--MySQL 优化"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-01-04</div><div class="title">实践一下--MySQL 优化</div></div></a></div><div><a href="/posts/27951/" title="学习--ElasticSearch"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-29</div><div class="title">学习--ElasticSearch</div></div></a></div><div><a href="/posts/39089/" title="实践一下--SpringBoot多模块项目"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-20</div><div class="title">实践一下--SpringBoot多模块项目</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">PaulGeorge</div><div class="author-info__description">很多事情就像是旅行一样，当你决定要出发的时候，最困难的那部分其实就已经完成了</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/PaulGeorge123"><i class="fab fa-github"></i><span>GitHub URL</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/PaulGeorge123" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#File%E7%B1%BB"><span class="toc-number">1.</span> <span class="toc-text">File类</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8"><span class="toc-number">1.1.</span> <span class="toc-text">作用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E8%B7%AF%E5%BE%84"><span class="toc-number">1.2.</span> <span class="toc-text">获取路径</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%A4%E6%96%AD%E6%96%87%E4%BB%B6%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8"><span class="toc-number">1.3.</span> <span class="toc-text">判断文件是否存在</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E3%80%81%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6"><span class="toc-number">1.4.</span> <span class="toc-text">创建、删除文件</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Paths%E7%B1%BB"><span class="toc-number">2.</span> <span class="toc-text">Paths类</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8-1"><span class="toc-number">2.1.</span> <span class="toc-text">作用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BD%AC%E6%8D%A2%E4%B8%BA%E8%B7%AF%E5%BE%84"><span class="toc-number">2.2.</span> <span class="toc-text">转换为路径</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Files%E7%B1%BB"><span class="toc-number">3.</span> <span class="toc-text">Files类</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8-2"><span class="toc-number">3.1.</span> <span class="toc-text">作用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%A4%E6%96%AD%E6%96%87%E4%BB%B6%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8-1"><span class="toc-number">3.2.</span> <span class="toc-text">判断文件是否存在</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6"><span class="toc-number">3.3.</span> <span class="toc-text">删除文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%96%87%E4%BB%B6%E5%8F%8A%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="toc-number">3.4.</span> <span class="toc-text">创建文件及文件夹</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%86%99%E6%96%87%E4%BB%B6"><span class="toc-number">3.5.</span> <span class="toc-text">写文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%AF%BB%E6%96%87%E4%BB%B6"><span class="toc-number">3.6.</span> <span class="toc-text">读文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8B%B7%E8%B4%9D%E6%96%87%E4%BB%B6"><span class="toc-number">3.7.</span> <span class="toc-text">拷贝文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A7%BB%E5%8A%A8%E6%96%87%E4%BB%B6"><span class="toc-number">3.8.</span> <span class="toc-text">移动文件</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#FileUtils"><span class="toc-number">4.</span> <span class="toc-text">FileUtils</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8-3"><span class="toc-number">4.1.</span> <span class="toc-text">作用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#maven%E4%BE%9D%E8%B5%96"><span class="toc-number">4.2.</span> <span class="toc-text">maven依赖</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8B%B7%E8%B4%9D%E6%96%87%E4%BB%B6-1"><span class="toc-number">4.3.</span> <span class="toc-text">拷贝文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A7%BB%E5%8A%A8%E6%96%87%E4%BB%B6-1"><span class="toc-number">4.4.</span> <span class="toc-text">移动文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B8%85%E7%A9%BA%E3%80%81%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="toc-number">4.5.</span> <span class="toc-text">清空、删除文件夹</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="toc-number">4.6.</span> <span class="toc-text">创建文件夹</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/47231/" title="POI读取Excel问题">POI读取Excel问题</a><time datetime="2023-04-11T01:00:00.000Z" title="发表于 2023-04-11 09:00:00">2023-04-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/8422/" title="Excel大文件的上传">Excel大文件的上传</a><time datetime="2023-04-10T01:00:00.000Z" title="发表于 2023-04-10 09:00:00">2023-04-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/55119/" title="每日一面--Files工具类">每日一面--Files工具类</a><time datetime="2023-01-01T01:00:00.000Z" title="发表于 2023-01-01 09:00:00">2023-01-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/34600/" title="面试一下--JUC入门">面试一下--JUC入门</a><time datetime="2022-09-10T01:00:00.000Z" title="发表于 2022-09-10 09:00:00">2022-09-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/16284/" title="每日一面--字符流和字节流">每日一面--字符流和字节流</a><time datetime="2022-07-01T01:00:00.000Z" title="发表于 2022-07-01 09:00:00">2022-07-01</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By PaulGeorge</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></body></html>